package com.udaos.modules.train.controllers;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.By;
import org.nutz.mvc.annotation.Filters;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import com.udaos.common.base.Result;
import com.udaos.common.filter.PrivateFilter;
import com.udaos.common.page.DataTableColumn;
import com.udaos.common.page.DataTableOrder;
import com.udaos.models.train.Ud_traincourse_product;
import com.udaos.modules.train.services.UdTraincourseProductService;


/**
 * @author Wizzer.cn
 * @time 2017-03-07 15:15:45
 * 
 */
@IocBean
@At("/platform/train/courseproduct")
@Filters({ @By(type = PrivateFilter.class)})
public class UdTraincourseProductController {
private static final Log log = Logs.get();
	@Inject
	private UdTraincourseProductService udTraincourseProductService;

	@At("")
	@Ok("beetl:/platform/train/courseproduct/index.html")
	@RequiresAuthentication
	public void index() {
		
	}
	
	@At
	@Ok("beetl:/platform/train/courseproduct/add.html")
	@RequiresAuthentication
	public void add() {
	
	}
	
	@At
	@Ok("json")
	public Object addDo(@Param("..") Ud_traincourse_product ud_traincourse_product, HttpServletRequest req) {
		try {
			udTraincourseProductService.insert(ud_traincourse_product);
			return Result.success("system.success");
		} catch (Exception e) {
			return Result.error("system.error");
		}
	}
	
	@At("/edit/?")
	@Ok("beetl:/platform/train/courseproduct/edit.html")
	@RequiresAuthentication
	public Object edit(String id) {
		return udTraincourseProductService.fetch(id);
	}
	
	@At
	@Ok("json")
	public Object editDo(@Param("..") Ud_traincourse_product ud_traincourse_product, HttpServletRequest req) {
		try {
			udTraincourseProductService.updateIgnoreNull(ud_traincourse_product);
			return Result.success("system.success");
		} catch (Exception e) {
			return Result.error("system.error");
		}
	}
	
	@At({"/delete","/delete/?"})
	@Ok("json")
	public Object delete(String id, HttpServletRequest req) {
		try {
				udTraincourseProductService.delete(id);
			return Result.success("system.success");
		} catch (Exception e) {
			return Result.error("system.error");
		}
	}
	
	@At
	@Ok("json:full")
	@RequiresAuthentication
	public Object data(@Param("length") int length, @Param("start") int start, @Param("draw") int draw, @Param("::order") List<DataTableOrder> order, @Param("::columns") List<DataTableColumn> columns) {
		Cnd cnd = Cnd.NEW();
		return udTraincourseProductService.data(length, start, draw, order, columns, cnd, null);
	}

}